package frame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.KeyStroke;


public class StudentMainFrame extends JFrame{
  StudentScendpanel studentScendpanel ;
    Course_ST_Panel course_st_panel = new Course_ST_Panel();
    CommonPanel currentPanel;
    private Action course = new AbstractAction("课程查看", new ImageIcon("images/sale.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(course_st_panel);
        }
    };
    private Action score = new AbstractAction("成绩查询", new ImageIcon("images/sale.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(studentScendpanel);
        }
    };

    public StudentMainFrame(String sno) {
        this.studentScendpanel = new StudentScendpanel(sno);
        JMenuBar menuBar = new JMenuBar();
        JMenu menu1 = new JMenu("基础设置");
        JMenu menu2 = new JMenu("成绩查看");
        menuBar.add(menu1);
        menuBar.add(menu2);

        menu1.add(course).setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_MASK));
//        menu1.add(student).setAccelerator(KeyStroke.getKeyStroke('s', InputEvent.CTRL_MASK));
        menu2.add(score).setAccelerator(KeyStroke.getKeyStroke('a',InputEvent.CTRL_MASK));
        //让界面作为第一显示界面
        this.add(course_st_panel);
        this.currentPanel = course_st_panel;

        this.setJMenuBar(menuBar);
        this.setTitle("学生成绩管理系统");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.setSize(1100,650);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    //切换各个界面
    private void changePanel(CommonPanel commonPanel) {
        //移除当前显示的JPanel
        this.remove(currentPanel);
        //添加需要显示的JPanel
        this.add(commonPanel);
        //设置当前的JPanel
        this.currentPanel = commonPanel;
        this.repaint();
        this.setVisible(true);
        //重新读取数据
        commonPanel.setViewDatas();
        //刷新列表
        commonPanel.clear();
    }

}
